package com.example.myapplication.adapter.recyclerViewAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.entity.Dj;

import java.util.ArrayList;
import java.util.List;

public class DjAdapter extends RecyclerView.Adapter<DjAdapter.DjHolder> {
    private Context context;
    private List<Dj.DjRadiosBean> djRadiosBeanList;
    private DjHorAdapter adapter;
    private static int limit=0;

    public void setData(List<Dj.DjRadiosBean> djRadiosBeanList){
        this.djRadiosBeanList = djRadiosBeanList;
        notifyDataSetChanged();
    }

    public DjAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public DjHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_dj_adapter,parent,false);
        return new DjHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull DjHolder holder, int position) {
         Dj.DjRadiosBean djRadiosBean = djRadiosBeanList.get(position);
         holder.dj_recommend.setText(djRadiosBean.getCategory());

    }

    @Override
    public int getItemCount() {
        return djRadiosBeanList==null?0:5;
    }

    class DjHolder extends RecyclerView.ViewHolder {
        RecyclerView recycle_view_dj;
        TextView dj_recommend;
        public DjHolder(@NonNull View itemView) {
            super(itemView);
            recycle_view_dj = itemView.findViewById(R.id.recycle_view_dj);
            dj_recommend = itemView.findViewById(R.id.dj_recommend);
            RecyclerView.LayoutManager manager_hor= new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false);
            recycle_view_dj.setLayoutManager(manager_hor);
            adapter = new DjHorAdapter();
            recycle_view_dj.setAdapter(adapter);
            loadData();
        }
    }
    private void loadData(){
        List<Dj.DjRadiosBean> list = new ArrayList<>();
        if(limit+5<30) {
            for (int i = limit; i < limit + 5; i++) {
                list.add(djRadiosBeanList.get(i));
            }
            limit += 5;
            adapter.setData(list, context);
        }
        //adapter.setData(djRadiosBeanList,context);
    }
}
